#ifndef __LIB_UVIEW_BITMAP_H
#define __LIB_UVIEW_BITMAP_H

#include <stdint.h>
#include "uview_color.h"

typedef struct
{
    uint32_t width;
    uint32_t height;
    uview_color_t *bits;
} uview_bitmap_t;

typedef struct 
{
    int x; //view x
    int y; //view y
    int bx; //bitmap x
    int by; //bitmap y
    int bw; //bitmap width
    int bh; //bitmap height
    uview_bitmap_t bmp; 
    uint8_t refresh;
}uview_io_t;

static inline void uview_bitmap_init(uview_bitmap_t *bmp,uint32_t width,uint32_t height,uview_color_t *bits)
{
    bmp->width=width;
    bmp->height=height;
    bmp->bits=bits;
}

static inline void uview_bitmpa_putpixel_unsafe(uview_bitmap_t *bmp,int x,int y,uview_color_t color)
{
    bmp->bits[y*bmp->width+x]=color;
}

static inline void uview_bitmap_getpixel_unsafe(uview_bitmap_t *bmp,int x,int y,uview_color_t *color)
{
    *color=bmp->bits[y*bmp->width+x];
}

uview_bitmap_t *uview_bitmap_create(uint32_t width, uint32_t height);
int uview_bitmap_destroy(uview_bitmap_t *bitmap);
void uview_bitmap_clear(uview_bitmap_t *bitmap);
void uview_bitmap_putpixel(uview_bitmap_t *bmp, int x, int y, uview_color_t color);
int uview_bitmap_getpixel(uview_bitmap_t *bmp, int x, int y, uview_color_t *color);
void uview_bitmap_vline(uview_bitmap_t *bmp, int x, int y1, int y2, uview_color_t color);
void uview_bitmap_hline(uview_bitmap_t *bmp, int x1, int x2, int y, uview_color_t color);
void uview_bitmap_line(uview_bitmap_t *bmp, int x1, int x2, int y1, int y2, uview_color_t color);
void uview_bitmap_rect_ex(uview_bitmap_t *bmp, int x1, int x2, int y1, int y2, uview_color_t color);
void uview_bitmap_rectfill_ex(uview_bitmap_t *bmp, int x1, int x2, int y1, int y2, uview_color_t color);
void uview_bitmap_bitblt(uview_bitmap_t *dest, int dest_x, int dest_y, uview_bitmap_t *src, int src_x, int src_y, uint32_t width, uint32_t height);

#endif